package GUI;


import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.Color;
import java.awt.Font;



/**
 * ClientGUI class extends AbstractGUI class.
 * this class is the boundary of the client controller.
 * @author Ofek-az
 *
 */
public class ClientGUI extends AbstractGUI {
	/**
	 * This the host text field.
	 */
	private JTextField hostTf;
	/**
	 * This the port text field.
	 */
	private JTextField portTf;
	/**
	 * This the connect button.
	 */
	private JButton btnConnect;
	
	
	/**
	 * This is the class constructor.
	 */
	public ClientGUI() {
		getContentPane().setBackground(new Color(100, 149, 237));
		
		initialize();
		
		
	}

	/* (non-Javadoc)
	 * @see GUI.AbstractGUI#initialize()
	 */
	public void initialize() {
		setTitle("Connect");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(400,300);
		setLocationRelativeTo(null);
		getContentPane().setLayout(null);
		
		JLabel lblHost = new JLabel("Host:");
		lblHost.setForeground(new Color(0, 0, 0));
		lblHost.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblHost.setBounds(90, 64, 46, 14);
		getContentPane().add(lblHost);
		
		hostTf = new JTextField();
		hostTf.setBounds(138, 61, 149, 20);
		getContentPane().add(hostTf);
		hostTf.setDocument(new JTextFieldLimit(45));
		hostTf.setText("localhost");
		
		JLabel lblPort = new JLabel("Port:");
		lblPort.setForeground(new Color(0, 0, 0));
		lblPort.setFont(new Font("Tahoma", Font.PLAIN, 11));
		lblPort.setBounds(90, 99, 46, 14);
		getContentPane().add(lblPort);
		
		portTf = new JTextField();
		portTf.setBounds(138, 96, 149, 20);
		getContentPane().add(portTf);
		portTf.setDocument(new JTextFieldLimit(10));
		portTf.setText("5000");
		
		btnConnect = new JButton("Connect");
		btnConnect.setBounds(164, 152, 89, 23);
		getContentPane().add(btnConnect);
		
		setVisible(true);
	}
	
	/**
	 * This method is the host text field getter.
	 * @return host as a string.
	 */
	public String getHostTf() {
		return hostTf.getText();
	}

	/**
	 * This method is the host text field getter.
	 * @return port as a string.
	 */
	public String getPortTf() {
		return portTf.getText();
	}

	/**
	 * This method adds an action listener to the connect button.
	 * @param listener the action listener.
	 */
	public void addConnectActionListener(ActionListener listener)
	{
		btnConnect.addActionListener(listener);
	}

	public JButton getBtnConnect() {
		return btnConnect;
	}

	public void setBtnConnect(JButton btnConnect) {
		this.btnConnect = btnConnect;
	}

	public void setHostTf(JTextField hostTf) {
		this.hostTf = hostTf;
	}

	public void setPortTf(JTextField portTf) {
		this.portTf = portTf;
	}

}
